package org.example.dao;

// 代理主题
public class StorageProxy implements Storage {

    // 真实主题
    Storage storage;

    @Override
    public void save(Object data) {
        System.out.println("检查数据是否合法:" + data);
        storage.save(data);
        System.out.println("验证数据是否保存成功:" + data);
    }

    public void setStorage(Storage storage) {
        this.storage = storage;
    }

    public static void main(String[] args) {
        StorageProxy storage = new StorageProxy();
        HardDisk hardDisk = new HardDisk();
        UsbDisk usbDisk = new UsbDisk();
        // 通过代理执行业务方法
        System.out.println("---------------------------");
        storage.setStorage(hardDisk);
        storage.save("书籍");
        System.out.println("---------------------------");
        storage.setStorage(usbDisk);
        storage.save("书籍");
        System.out.println("---------------------------");

    }
}
